#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
int T,ans,ans1;
int n,m,L,V;
int a[N],d[N],v[N],p[N];
int main(){
    freopen("detect.in","w",stdin);
    freopen("detect.out","r",stdout);
    cin>>T;
    for(int i=1;i<=T;i++){
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int j=1;j<=m;j++){
            cin>>p[j];
        }
        for(int i=1;i<=n;i++){
        if(d[i]>p[m])continue;
        else{
            int s=lower_bound(p+1,p+n+1,d[i])-p;
            if(v[i]>V)ans++;
            if(s!=d[i])ans1=min(ans1,1);
        }
        cout<<ans<<" "<<m-ans1<<endl;
    }
    }

    return 0;
}

